package il.ac.technion.wiki.impl.tests;

import il.ac.technion.wiki.api.IContentImporter;
import il.ac.technion.wiki.api.IContentImporter.ContentException;
import il.ac.technion.wiki.impl.WikiImporter;
import junit.framework.TestCase;

import org.junit.Test;


public class TestWikiImporter extends TestCase{
	@Test
	public void test() throws ContentException{
		IContentImporter wi = new WikiImporter();
		StringBuilder sb = null;
		
		sb = new StringBuilder();		
		sb.append("<html>\n");
		sb.append("<body>\n");
		sb.append("\n");
		sb.append("<h1>My First Heading</h1>\n");
		sb.append("\n");
		sb.append("<p>My first paragraph.</p>\n");
		sb.append("\n");
		sb.append("</body>\n");
		sb.append("</html>\n");
		String actual = sb.toString();
		
		sb = new StringBuilder();
		sb.append("\n");
		sb.append("\n");
		sb.append("\n");
		sb.append("My First Heading\n");
		sb.append("\n");
		sb.append("My first paragraph.\n");
		sb.append("\n");
		sb.append("\n");
		sb.append("\n");
		
		String expected = sb.toString();
		assertEquals(expected, wi.process(actual.getBytes()));
		
		sb = new StringBuilder();		
		sb.append("<html>\n");
		sb.append("<body>\n");
		sb.append("\n");
		sb.append("<!--This\n\n\n\n\n comment wj\t\t\\\tt\t323##$%@ill not bycytutyjne displrtezrtnertxeayrtxndrtxtyrcned><.<<.><,,,,.<.<.<ertnxertx>,./,./,.jghfghrterxertzxergeexr/.-->\n");
		sb.append("<p>This is a regular paragraph</p>\n");
		sb.append("--->-->-._.__>>\n");
		sb.append("</body>\n");
		sb.append("</html>\n");
		actual = sb.toString();
		
		sb = new StringBuilder();
		sb.append("\n");
		sb.append("\n");
		sb.append("\n");
		sb.append("\n");
		sb.append("This is a regular paragraph\n");
		sb.append("--->-->-._.__>>\n");
		sb.append("\n");
		sb.append("\n");
		
		expected = sb.toString();
		assertEquals(expected, wi.process(actual.getBytes()));
		
		sb = new StringBuilder();		
		sb.append("<html>\n");
		sb.append("<body>\n");
		sb.append("\n");
		sb.append("<p>\n");
		sb.append("<a href=\"#C4\">See also Chapter 4.</a>\n");
		sb.append("</p>\n");
		sb.append("\n");
		sb.append("<h2>Chapter 1</h2>\n");
		sb.append("<p>This chapter explains ba bla bla</p>\n");
		sb.append("\n");
		sb.append("<h2>Chapter 2</h2>\n");
		sb.append("<p>This chapter explains ba bla bla</p>\n");
		sb.append("\n");
		sb.append("<h2>Chapter 3</h2>\n");
		sb.append("<p>This chapter explains ba bla bla</p>\n");
		sb.append("\n");
		sb.append("<h2><a name=\"C4\">Chapter 4</a></h2>\n");
		sb.append("<p>This chapter explains ba bla bla</p>\n");
		sb.append("\n");
		sb.append("<h2>Chapter 5</h2>\n");
		sb.append("<p>This chapter explains ba bla bla</p>\n");
		sb.append("\n");
		sb.append("<h2>Chapter 6</h2>\n");
		sb.append("<p>This chapter explains ba bla bla</p>\n");
		sb.append("\n");
		sb.append("<h2>Chapter 7</h2>\n");
		sb.append("<p>This chapter explains ba bla bla</p>\n");
		sb.append("\n");
		sb.append("<h2>Chapter 8</h2>\n");
		sb.append("<p>This chapter explains ba bla bla</p>\n");
		sb.append("\n");
		sb.append("<h2>Chapter 9</h2>\n");
		sb.append("<p>This chapter explains ba bla bla</p>\n");
		sb.append("</body>\n");
		sb.append("</html>\n");
		actual = sb.toString();
		
		sb = new StringBuilder();
		sb.append("\n");
		sb.append("\n");
		sb.append("\n");
		sb.append("\n");
		sb.append("See also Chapter 4.\n");
		sb.append("\n");
		sb.append("\n");
		sb.append("Chapter 1\n");
		sb.append("This chapter explains ba bla bla\n");
		sb.append("\n");
		sb.append("Chapter 2\n");
		sb.append("This chapter explains ba bla bla\n");
		sb.append("\n");
		sb.append("Chapter 3\n");
		sb.append("This chapter explains ba bla bla\n");
		sb.append("\n");
		sb.append("Chapter 4\n");
		sb.append("This chapter explains ba bla bla\n");
		sb.append("\n");
		sb.append("Chapter 5\n");
		sb.append("This chapter explains ba bla bla\n");
		sb.append("\n");
		sb.append("Chapter 6\n");
		sb.append("This chapter explains ba bla bla\n");
		sb.append("\n");
		sb.append("Chapter 7\n");
		sb.append("This chapter explains ba bla bla\n");
		sb.append("\n");
		sb.append("Chapter 8\n");
		sb.append("This chapter explains ba bla bla\n");
		sb.append("\n");
		sb.append("Chapter 9\n");
		sb.append("This chapter explains ba bla bla\n");
		sb.append("\n");
		sb.append("\n");
		
		expected = sb.toString();
		assertEquals(expected, wi.process(actual.getBytes()));
		
		
		
		
		sb = new StringBuilder();		
		sb.append("<html>\n");
		sb.append("<body>\n");
		sb.append("\n");
		sb.append("<p>An image from another folder:</p>\n");
		sb.append("<img src=\"/images/chrome.gif\" alt=\"Google Chrome\" width=\"33\" height=\"32\" />\n");
		sb.append("\n");
		sb.append("<p>An image from W3Schools:</p>\n");
		sb.append("<img src=\"http://www.w3schools.com/images/w3schools_green.jpg\" alt=\"W3Schools.com\" width=\"104\" height=\"142\" />\n");
		sb.append("\n");
		sb.append("</body>\n");
		sb.append("</html>\n");
		actual = sb.toString();
				
		sb = new StringBuilder();		
		sb.append("\n");
		sb.append("\n");
		sb.append("\n");
		sb.append("An image from another folder:\n");
		sb.append("\n");
		sb.append("\n");
		sb.append("An image from W3Schools:\n");
		sb.append("\n");
		sb.append("\n");
		sb.append("\n");
		sb.append("\n");
		
		expected = sb.toString();
		assertEquals(expected, wi.process(actual.getBytes()));
		
	}
}
